package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MrDeviceProtocolConfiguration;
import com.ruoyi.system.service.IMrDeviceProtocolConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备协议配置Controller
 *
 * @author lsw
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/system/configuration")
public class MrDeviceProtocolConfigurationController extends BaseController
{
    @Autowired
    private IMrDeviceProtocolConfigurationService mrDeviceProtocolConfigurationService;

    /**
     * 查询设备协议配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo list(MrDeviceProtocolConfiguration mrDeviceProtocolConfiguration)
    {
        startPage();
        List<MrDeviceProtocolConfiguration> list = mrDeviceProtocolConfigurationService.selectMrDeviceProtocolConfigurationList(mrDeviceProtocolConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出设备协议配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "设备协议配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MrDeviceProtocolConfiguration mrDeviceProtocolConfiguration)
    {
        List<MrDeviceProtocolConfiguration> list = mrDeviceProtocolConfigurationService.selectMrDeviceProtocolConfigurationList(mrDeviceProtocolConfiguration);
        ExcelUtil<MrDeviceProtocolConfiguration> util = new ExcelUtil<MrDeviceProtocolConfiguration>(MrDeviceProtocolConfiguration.class);
        util.exportExcel(response, list, "设备协议配置数据");
    }

    /**
     * 获取设备协议配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mrDeviceProtocolConfigurationService.selectMrDeviceProtocolConfigurationById(id));
    }

    /**
     * 新增设备协议配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "设备协议配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MrDeviceProtocolConfiguration mrDeviceProtocolConfiguration)
    {
        return toAjax(mrDeviceProtocolConfigurationService.insertMrDeviceProtocolConfiguration(mrDeviceProtocolConfiguration));
    }

    /**
     * 修改设备协议配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "设备协议配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MrDeviceProtocolConfiguration mrDeviceProtocolConfiguration)
    {
        return toAjax(mrDeviceProtocolConfigurationService.updateMrDeviceProtocolConfiguration(mrDeviceProtocolConfiguration));
    }

    /**
     * 删除设备协议配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "设备协议配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mrDeviceProtocolConfigurationService.deleteMrDeviceProtocolConfigurationByIds(ids));
    }
}

